import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WindowKeyEvent extends JFrame implements KeyListener {
   JButton b;
   WindowKeyEvent() {
      setLayout(new FlowLayout());
      b=new JButton("Ctrl+X或Shift+X,");
      b.addKeyListener(this);
      add(b);
      setBounds(10,10,300,300);
      setVisible(true); 
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
   public void keyPressed(KeyEvent e) {
      JButton button=(JButton)e.getSource();
      int x=0,y=0,w=0,h=0;
      x=button.getBounds().x;
      y=button.getBounds().y;
      w=button.getBounds().width;
      h=button.getBounds().height;     
      if(e.getModifiers()==InputEvent.SHIFT_MASK&&e.getKeyCode()==KeyEvent.VK_X)
          button.setLocation(y,x);
      else if(e.getModifiers()==InputEvent.CTRL_MASK&&e.getKeyCode()==KeyEvent.VK_X)
          button.setSize(h,w);
   }
   public void keyTyped(KeyEvent e) {}
   public void keyReleased(KeyEvent e) {}
}
